﻿using System;
using System.Buffers;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RescueApp.Data;
using RescueApp.Model;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace RescueApp.UI
{

    public partial class ResultRescue : Form
    {
        public static string ConnectingStr = "Server=LAPTOP-1BOQI73G;Database=Rescue;TrustServerCertificate=True;Integrated Security=True;";
        RescueContext db = new RescueContext(ConnectingStr);
        public ResultRescue()
        {
            InitializeComponent();
        }

        public ResultRescue(RescueContext db)
        {
            InitializeComponent();
            this.db = db;
        }

        private void ResultRescue_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string input = textBox1.Text.Trim();

            // 输入转换为整数
            if (!int.TryParse(input, out int searchValue))
            {
                MessageBox.Show("输入空白. 请输入查询内容.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            // 查询数据库
            var result = db.RescueApplies.FirstOrDefault(rd => rd.RescueID == searchValue);

         

            if (result != null)
            {
               
                MessageBox.Show(
                                $"救援申请ID: {result.RescueID}\n" +
                                $"故障车车牌: {result.LicenseID}\n" +
                                $"故障车型: {result.CarType}\n" +
                                $"驾驶证: {result.DriverLicenseID}\n" +
                                $"申请人电话: {result.Phone}\n" +
                                $"故障地点: {result.RescueLocation}\n"+
                                 $"维修目的地: {result.Destination}\n"+
                                 $"申请日期: {result.RescueLocation}",
                                "救援申请信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {

                MessageBox.Show("没有找到该救援申请信息.", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
